home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Magazin/MacEasy 2
/
Mac Magazin and MacEasy Magazine CD - Issue 02.iso
/
Sharewarebibliothek
/
Applikationen
/
Alpha.5.81 folder
/
Tcl
/
UserCode
/
Text Filters
/
Text Munging
/
wordcount
< prev
Wrap
Text File
|
1993-10-19
|
665b
|
23 lines
#!/usr/bin/perl
$/ = ""; # Enable paragraph mode.
$* = 1; # Enable multi-line patterns.
# Now read each paragraph and split into words. Record each
# instance of a word in the %wordcount associative array.
while (<>) {
s/-\n//g; # Dehyphenate hyphenations.
tr/A-Z/a-z/; # Canonicalize to lower case.
@words = split(/\W*\s+\W*/, $_);
foreach $word (@words) {
$wordcount{$word}++; # Increment the entry.
}
}
# Now print out all the entries in the %wordcount array.
foreach $word (sort keys(%wordcount)) {
printf "%20s %d\n", $word, $wordcount{$word};
}